package webmarket;

/**
 * @author Simos
 */

import model.Customer;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.swing.JOptionPane;

public class UserFrame extends javax.swing.JFrame {

    /**
     * Creates new form UserFrame
     */

    Customer logedUser;
    
    public UserFrame() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        userMarketButton = new javax.swing.JButton();
        userProfileButton = new javax.swing.JButton();
        ExitButton = new javax.swing.JButton();
        logedUserText1 = new javax.swing.JTextField();
        logedUserText2 = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("WebMarket - Κεντρικό μενού");

        jLabel1.setText("Έχετε συνδεθεί ως :");

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        jLabel2.setForeground(new java.awt.Color(0, 51, 204));
        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel2.setText("Επιλέξτε κατηγορία εργασιών");

        userMarketButton.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        userMarketButton.setText("Αγορά προϊόντων");
        userMarketButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                userMarketButtonActionPerformed(evt);
            }
        });

        userProfileButton.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        userProfileButton.setText("Διαχείριση Προφίλ");
        userProfileButton.setMaximumSize(new java.awt.Dimension(195, 31));
        userProfileButton.setMinimumSize(new java.awt.Dimension(195, 31));
        userProfileButton.setPreferredSize(new java.awt.Dimension(195, 31));
        userProfileButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                userProfileButtonActionPerformed(evt);
            }
        });

        ExitButton.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        ExitButton.setForeground(new java.awt.Color(0, 51, 204));
        ExitButton.setText("Έξοδος");
        ExitButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ExitButtonActionPerformed(evt);
            }
        });

        logedUserText1.setEnabled(false);
        logedUserText1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                logedUserText1ActionPerformed(evt);
            }
        });

        logedUserText2.setEnabled(false);
        logedUserText2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                logedUserText2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(70, 70, 70)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 360, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addComponent(userMarketButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(userProfileButton, javax.swing.GroupLayout.DEFAULT_SIZE, 360, Short.MAX_VALUE))))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(165, 165, 165)
                                .addComponent(ExitButton, javax.swing.GroupLayout.PREFERRED_SIZE, 161, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(0, 60, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(logedUserText1, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(2, 2, 2)
                        .addComponent(logedUserText2, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(logedUserText2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(logedUserText1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(45, 45, 45)
                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(45, 45, 45)
                .addComponent(userProfileButton, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(45, 45, 45)
                .addComponent(userMarketButton, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(45, 45, 45)
                .addComponent(ExitButton, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(45, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void userMarketButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_userMarketButtonActionPerformed
        UserMarket usermarket = new UserMarket();
        usermarket.setLogedUser(logedUser);
        usermarket.setLocationRelativeTo(null);
        usermarket.setVisible(true);
        dispose();
    }//GEN-LAST:event_userMarketButtonActionPerformed

    private void userProfileButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_userProfileButtonActionPerformed
        UserProfile userprofile = new UserProfile();
        userprofile.setLogedUser(logedUser);
        userprofile.setLocationRelativeTo(null);
        userprofile.setVisible(true);
        dispose();
    }//GEN-LAST:event_userProfileButtonActionPerformed

    private void ExitButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ExitButtonActionPerformed
      
        int holdExit = JOptionPane.showConfirmDialog(this, "Σίγουρα ζητήσατε την έξοδο σας από το WebMarket...     ", "     WebMarket", JOptionPane.YES_NO_OPTION);

        if (holdExit != 0)
        return;
               
        
        JOptionPane.showMessageDialog(rootPane ,"Σας ευχαριστούμε για την εμπιστοσύνη σας...     " ,"     WebMarket",1);
        
        LoginFrame loginFrame = new LoginFrame();
 //     loginFrame.setLogedUser(logedUser); 
        loginFrame.setLocationRelativeTo(null);
        loginFrame.setVisible(true);
        dispose();
                
    }//GEN-LAST:event_ExitButtonActionPerformed

    private void logedUserText1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_logedUserText1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_logedUserText1ActionPerformed

    private void logedUserText2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_logedUserText2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_logedUserText2ActionPerformed

    public void setLogedUser (Customer logedUser){
        this.logedUser = logedUser;
        logedUserText1.setText(logedUser.getFirstName());
        logedUserText2.setText(logedUser.getLastName()); 
    }
    
    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(AdminProduct.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(AdminProduct.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(AdminProduct.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(AdminProduct.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new UserFrame().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton ExitButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JTextField logedUserText1;
    private javax.swing.JTextField logedUserText2;
    private javax.swing.JButton userMarketButton;
    private javax.swing.JButton userProfileButton;
    // End of variables declaration//GEN-END:variables
}